import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class GetIcon {
    public Icon getIcon(String iconName, int width, int height) {

        BufferedImage originalImage = null;
        try {
            originalImage = ImageIO.read(new File("images/"+iconName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        int newWidth = width;
        int newHeight = height;

        // 创建缩放后的图像
        Image scaledImage = originalImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
        ImageIcon icon = new ImageIcon(scaledImage);
        return icon;
    }
}
